package com.example.administrator.yunniuusedcar.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.common.base.BaseActivity;
import com.example.administrator.common.base.BaseFragment;
import com.example.administrator.common.base.Global;
import com.example.administrator.yunniuusedcar.R;
import com.example.administrator.yunniuusedcar.adapter.JiFenShoppingAdapter;
import com.example.administrator.yunniuusedcar.model.mode_benn.IHttpService;
import com.example.administrator.yunniuusedcar.model.mode_benn.JiFenShoppingBean;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import okhttp3.Call;

/**
 * 首页 -->  豪车积分 （RecycleView） 积分商城     （待改）
 */
public class HaoCarJifenShopActivity extends BaseActivity {

    private ImageView ivJifenpager;
    private TextView tvTitle3;
    private TextView tvMoney3;
    private RecyclerView mRVOrder;
    private JiFenShoppingAdapter mAdapter;
    private JiFenShoppingBean jiFenShoppingBean;


    @Override
    public int getLayoutRes() {

        return R.layout.item_recycleview2;
    }   //item_recycleview2   fragment_glide_jifen_sport

    @Override
    public void initView() {
        initFragView();
    }

    private void initFragView() {   //空件
        mRVOrder = findView(R.id.recycler_view6);


        mRVOrder.setLayoutManager(new GridLayoutManager(this,2,RecyclerView.VERTICAL,
               false));
        //设置adapter
        mAdapter = new JiFenShoppingAdapter(this,lisData);
        mRVOrder.setAdapter(mAdapter);

    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {
        // 加载数据
        initUloadMenuInfor();

    }

        ArrayList<JiFenShoppingBean> lisData = new ArrayList();

    // ArrayList<JiFenShoppingBean.DataX> listDatas = new ArrayList();
    private void initUloadMenuInfor() {    // 加载数据

        String ul = IHttpService.HOST_URL + "goods/getlist";    // 商品详情
//        String vals = "06a96b0bKp0f6fx4kdONF5h3ywpqULc+FZTxA44FJ10ZHdCsQs+u7iFizfbnOjU";

        OkHttpUtils.post().url(ul).addParams("sign", IHttpService.SignVal).addParams("page", "1").build().execute(new StringCallback() {


            @Override
            public void onError(Call call, Exception e, int id) {
      Global.showToast("商品详情、请求超时！！"+ e.getMessage());
            System.out.println("-----====----------A"+ e);
            }

            @Override
            public void onResponse(String response, int id) {
//      Global.showToast("====="+response);
                    System.out.println("-----====-----------A1"+response);
                Gson js = new Gson();
                //积分商城  积分首页
                jiFenShoppingBean = js.fromJson(response, JiFenShoppingBean.class);

                lisData.add(jiFenShoppingBean);
                mAdapter.setDatas(lisData);    //适配器
                   mAdapter.notifyDataSetChanged();

            }
        });
    }

    ///////////////////////////////////////////////
//    @Override
//    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//        // TODO: inflate a fragment view
//        View rootView = super.onCreateView(inflater, container, savedInstanceState);
//        unbinder = ButterKnife.bind(this, rootView);
//        return rootView;
//    }
//
//    @Override
//    public void onDestroyView() {
//        super.onDestroyView();
//        unbinder.unbind();
//    }
//
//    ////////////////////////////////////////
//
//
//    class BeFragAdapter extends RecyclerView.Adapter<BeFragAdapter.MyViewHolder> {
//
//        @BindView(R.id.iv_Jifenpager)
//        ImageView ivJifenpager2;
//        @BindView(R.id.tv_title3)
//        TextView tvTitle;
//        @BindView(R.id.tv_Money3)
//        TextView tvMoney;
//        //  <泛型 《类内部类》 >
//        private BeFragAdapter MyAdapter;
//
//        @Override
//        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//            MyViewHolder holder = new MyViewHolder(LayoutInflater.from(getContext())
//                    .inflate(R.layout.fragment_glide_jifen_sport, parent, false));
//            return holder;
//        }
//
//        @Override  // 拿到控件后 设值得地方
//        public void onBindViewHolder(MyViewHolder holder, int position) {
//            // setText:
//            Picasso.with(getContext()).load(JiFenShoppingBean.DataX.Data+)    //iv_Jifenpager
//
////            mFLOrderInf.setOnClickListener(new View.OnClickListener() {
////                @Override
////                public void onClick(View v) {
////                    Intent intent = new Intent(getActivity(),OrderInformationFragment.class);
////                    startActivity(intent);
////
////                }
////            });
//        }
//
//        @Override
//        public int getItemCount() {
//            if (JiFenShoppingBean == null) {
//                return 0;
//            } else {
//                return JiFenShoppingBean == null ? 0 : JiFenShoppingBean.size();
//
//            }
//        }
//
//        /////////////////////////////////////////////////////////////////////////////////////////
//
//        /**
//         * *************************************************************************************
//         */
//
//        class MyViewHolder extends RecyclerView.ViewHolder {
//
//            private TextView mOrderId;
//            private TextView mOrderCount;
//            private TextView mOrderStatus;
//            private TextView mOrdetTime;
//            private TextView mOrderTop;
//            private TextView mOrderDelete;
//
//            public MyViewHolder(View itemView) {
//                super(itemView);
//                mOrderId = itemView.findViewById(R.id.tv_order_id);
//                mOrderCount = itemView.findViewById(R.id.tv_order_count);
//                mOrderStatus = itemView.findViewById(R.id.tv_order_status);
//                mOrdetTime = itemView.findViewById(R.id.tv_order_time);
//
//                mOrderTop = itemView.findViewById(R.id.tv_set_Top);  //置顶
//                mOrderDelete = itemView.findViewById(R.id.tv_delete);  // 删除
//            }
//        }
//    }
}

